package com.student.liu.service.impl;

import com.student.liu.exception.ServiceValidationException;
import com.student.liu.service.IAdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * 管理员 服务接口 实现类
 */
@Slf4j
@Service
public class AdminServiceImpl implements IAdminService {

    @Resource
    RedisTemplate redisTemplate;

    @Override
    public void login(String username, String password) {
        String redisPassword = redisTemplate.opsForValue().get(username).toString();    //从Redis里面取出的密码
        log.info("redisPassword:" + redisPassword);
        if (!password.equals(redisPassword)) {
            throw new ServiceValidationException("登录失败，账号或密码错误", 401);
        }
    }

    @Override
    public void changePwd(String username, String newPassword) {
        redisTemplate.opsForValue().set(username, newPassword);
    }

}
